﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.InfoCollect
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.Common.Enums.System
@using EnumHelper = ZBJF.Warranty.Common.Common.EnumHelper
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    byte collectWithType;
    byte.TryParse(PageData["CollectWithType"] == null ? "" : PageData["CollectWithType"].ToString(), out collectWithType);
    if (collectWithType < 1)
    {
        byte.TryParse(ViewBag.CollectWithType == null ? "" : ViewBag.CollectWithType.ToString(), out collectWithType);
    }
    string type = PageData["Type"];//是否是显示收集结果ShowResult
    if (string.IsNullOrEmpty(type))
    {
        type = ViewBag.Type != null ? ViewBag.Type.ToString() : "";
    }

    var cellPhoneInsuranceInfo = ServiceFactory.CellPhoneInsuranceInfoServiceInstance.Load(
        Model.InsuranceOrderServiceProjectId ?? 0);
    var cellPhoneServiceProjectID = cellPhoneInsuranceInfo != null && cellPhoneInsuranceInfo.CellPhoneServiceProjectID.HasValue
        ? cellPhoneInsuranceInfo.CellPhoneServiceProjectID.Value
        : 0;
    var serviceProjectType = (ServiceProductType)(Model.ServiceProjectType ?? 0);

    var infoCollectItems = ServiceFactory.InsuranceProductInfoCollectItemSnapshootServiceInstance.GetInsuranceProductInfoCollectItemSnapshoot(cellPhoneServiceProjectID, serviceProjectType, collectWithType).ToList();
    //如果快照不存在，去产品配置中取
    if (!infoCollectItems.Any())
    {
        infoCollectItems = ServiceFactory.InsuranceProductsInfoCollectItemMappingsServiceInstance.LoadInfoCollectItems(new List<int> { cellPhoneServiceProjectID }, collectWithType);
    }
}
<div id="divInfoCollectItems_@(collectWithType)">
    <h4>
        @EnumHelper.Instance.GetDescription(typeof(CollectWithType), collectWithType)
    </h4>
    @if (type == "ShowResult")
    {
        <table class="table table-responsive table-bordered table-hover">
            <tr>
                <th>资料类型</th>
                <th>需上传图片数</th>
                <th>已上传图片数</th>
                <th>查看图片</th>
                <th>上传人</th>
                <th>上传时间</th>
            </tr>
            @for (int i = 0; i < infoCollectItems.Count; i++)
            {
                var infoCollectItem = infoCollectItems[i];
                var hasCollectItem = ServiceFactory.InsuranceWarrantyRecordInfoCollectServiceInstance.Load(Model.ID, (byte)collectWithType, infoCollectItem.InfoCollectItemID);
                var uploadFiles = ServiceFactory.UploadFilesServiceInstance.GetFiles(NeedUploadFileDataTableEnums.InsuranceWarrantyRecordInfoCollect, hasCollectItem != null ? hasCollectItem.ID : 0);
                var imageUrls = uploadFiles.Any() ? uploadFiles.Select(o => o.FilePath).ToList().Aggregate(string.Empty, (c, d) => c + ';' + d).Trim(';') : "";
                <tr>
                    <td>
                        @infoCollectItem.InfoCollectItemName
                    </td>
                    <td>
                        @infoCollectItem.CanUploadPicCount
                    </td>
                    <td>
                        @(hasCollectItem != null ? hasCollectItem.HadUploadPicCount : 0)
                    </td>
                    <td>
                        @if (hasCollectItem != null)
                        {
                            <a class='Edit-R' href='javascript:void(0);' onclick="showImageLayer(this, 'MultiImageLook.html')" imgurl="@(imageUrls)">
                                查看图片
                            </a>
                        }
                    </td>
                    <td>
                        @(hasCollectItem != null ? hasCollectItem.CreateBy : "")
                    </td>
                    <td>
                        @(hasCollectItem != null ? hasCollectItem.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") : "")
                    </td>
                </tr>
            }
        </table>
    }
    else
    {
        <table class="table table-responsive table-bordered table-hover">
            <tr>
                <th>资料类型</th>
                <th>需上传图片数</th>
                <th>已上传图片数</th>
                <th>查看图片</th>
                <th>上传人</th>
                <th>上传时间</th>
                <th>操作</th>
            </tr>
            @for (int i = 0; i < infoCollectItems.Count; i++)
            {
                var infoCollectItem = infoCollectItems[i];
                var hasCollectItem = ServiceFactory.InsuranceWarrantyRecordInfoCollectServiceInstance.Load(Model.ID, collectWithType, infoCollectItem.InfoCollectItemID);
                var uploadFiles = ServiceFactory.UploadFilesServiceInstance.GetFiles(NeedUploadFileDataTableEnums.InsuranceWarrantyRecordInfoCollect, hasCollectItem != null ? hasCollectItem.ID : 0);
                var imageUrls = uploadFiles.Any() ? uploadFiles.Select(o => o.FilePath).ToList().Aggregate(string.Empty, (c, d) => c + ';' + d).Trim(';') : "";
                <tr>
                    <td>
                        @infoCollectItem.InfoCollectItemName
                    </td>
                    <td>
                        <label class="InfoCollectCanUploadPicCount" id="InfoCollectCanUploadPicCount_@i">@infoCollectItem.CanUploadPicCount</label>
                    </td>
                    <td>
                        <label id="InfoCollectHadUploadPicCount_@i">@(hasCollectItem != null ? hasCollectItem.HadUploadPicCount : 0)</label>
                    </td>
                    <td>
                        @if (hasCollectItem != null)
                        {
                            <a class='Edit-R' href='javascript:void(0);' onclick='showImageLayer(this,"multiimagelook.html")' imgurl="@(imageUrls)">
                                查看图片
                            </a>
                        }
                    </td>
                    <td>
                        @(hasCollectItem != null ? hasCollectItem.CreateBy : "")
                    </td>
                    <td>
                        @(hasCollectItem != null ? hasCollectItem.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") : "")
                    </td>
                    <td>
                        <a class='Edit-R' href='javascript:void(0);' onclick='showLayerOpen("信息收集", "/PubModelDialog/InfoCollectDialog?ID=@(hasCollectItem != null ?hasCollectItem.ID:-1)&amp;InsuranceWarrantyRecordID=@Model.ID&amp;InfoCollectWith=@((byte)collectWithType)&amp;InfoColectItemID=@(infoCollectItem.InfoCollectItemID)&amp;InfoColectItemName=@(infoCollectItem.InfoCollectItemName)&amp;NeedUploadPicCount=@(infoCollectItem.CanUploadPicCount)","800px","600px")'>
                            上传图片
                        </a>
                    </td>
                </tr>
            }
        </table>
    }
</div>